//本地环境
//var baseurl="http://localhost:8080?t="+getsjc()+"/#";//访问域名
//var apiurl="http://192.168.1.128:8080";//接口域名

// 蝌蚪pc后台
   var baseurl = "http://adminpc.tongdui365.com?t=" + getsjc() + "/#"; //访问域名
   var mapurl = "http://adminpc.tongdui365.com/";
   var apiurl = "http://kedoucloud.tongdui365.com"; //接口域名
   var wgmurl = "http://kedoujfapp.tongdui365.com";//物格码接口地址
   var baseurl = "http://localhost:8080?t=" + getsjc() + "/#"; //访问域名

   localStorage.setItem("webtype", "index");
   var webtitle = "蝌蚪社群";
     var appid='wxa177d8770820ed4b' //蝌蚪appid




var imguploadurl="http://storage.tongdui365.com/imgUpload/single"
var pageSize = 10; //分页显示条数
$(document).ready(function() {
  if (!localStorage.getItem("type")) {
    //location.href = '/login.html'; //后台主页
  }
});
function getsjc(time) {
  /*时间转时间戳*/
  if (time) {
    if (time.indexOf("-") >= 0) {
      var date = new Date(Date.parse(time.replace(/-/g, "/")));
    } else {
      var date = new Date(time);
    }
  } else {
    var date = new Date();
  }
  var time1 = date.getTime();
  return time1;
}

//当前时间年月日时分
function getLocalTime(nS) {
  var time = new Date(parseInt(nS) * 1000);
  var y = time.getFullYear();
  var m = time.getMonth() + 1;
  var d = time.getDate();
  var h = time.getHours();
  var mm = time.getMinutes();
  var s = time.getSeconds();
  return y + "-" + m + "-" + d + " " + h + ":" + mm;
}
//当前时间年月日时分秒
function getnowtime(type) {
  var myDate = new Date();
  var year = myDate.getFullYear();
  var month = myDate.getMonth() + 1;
  var date = myDate.getDate();
  var h = myDate.getHours();
  var m = myDate.getMinutes();
  var s = myDate.getSeconds();
  if (type == 1) {
    var now = year + "-" + p(month) + "-" + p(date); //年月日
  } else if (type == 2) {
    var now = year + "-" + p(month) + "-" + p(date) + " " + p(h) + ":" + p(m); //年月日时分
  } else if (type == 3) {
    var now = p(h) + ":" + p(m) + ":" + p(s); //时分秒
  } else {
    var now =
      year +
      "-" +
      p(month) +
      "-" +
      p(date) +
      " " +
      p(h) +
      ":" +
      p(m) +
      ":" +
      p(s); //年月日时分秒
  }
  return now;
}

//日期时间戳格式化
function FormatDate(strTime, type) {
  if (strTime == null) {
    return "";
  }
  var Mytime = "";
  var date = new Date(strTime);
  var myYear = date.getFullYear();
  var myMonth = date.getMonth() + 1;
  var myDate = date.getDate();
  var myHours = date.getHours();
  var myMinutes = date.getMinutes();
  var mySeconds = date.getSeconds();
  if (myMonth < 10) {
    myMonth = "0" + myMonth;
  }
  if (myDate < 10) {
    myDate = "0" + myDate;
  }
  if (myMinutes < 10) {
    myMinutes = "0" + myMinutes;
  }
  if (mySeconds < 10) {
    mySeconds = "0" + mySeconds;
  }
  if (myHours < 10) {
    myHours = "0" + myHours;
  }
  if (type == 1) {
    Mytime = myDate + " " + myHours + ":" + myMinutes;
  } else if (type == 2) {
    Mytime = myYear + "-" + myMonth + "-" + myDate;
  } else if (type == 3) {
    Mytime =
      myYear +
      "-" +
      myMonth +
      "-" +
      myDate +
      " " +
      myHours +
      ":" +
      myMinutes +
      ":" +
      mySeconds;
  } else if (type == 4) {
    Mytime = myMonth + "-" + myDate + " " + myHours + "点";
  } else {
    Mytime =
      myYear + "-" + myMonth + "-" + myDate + " " + myHours + ":" + myMinutes;
  }
  return Mytime;
}

function p(s) {
  return s < 10 ? "0" + s : s;
}

//当前时间和后一天
function getQHTime(type) {
  //type：1是当前时间，2是后一天
  var Mytime = "";
  var myDate = new Date();
  var year = myDate.getFullYear();
  var month = myDate.getMonth() + 1;
  var date = myDate.getDate();
  var hours = myDate.getHours();
  var minutes = myDate.getMinutes();
  var seconds = myDate.getSeconds();
  if (month < 10) {
    month = "0" + month;
  }
  if (date < 10) {
    date = "0" + date;
  }
  if (hours < 10) {
    hours = "0" + hours;
  }
  if (minutes < 10) {
    minutes = "0" + minutes;
  }
  if (seconds < 10) {
    seconds = "0" + seconds;
  }
  var nextDate = new Date(myDate.getTime() + 24 * 60 * 60 * 1000); //后一天，前一天为-24*60*60*1000
  var hyear = nextDate.getFullYear();
  var hmonth = nextDate.getMonth() + 1;
  var hdate = nextDate.getDate();
  var hhours = nextDate.getHours();
  var hminutes = nextDate.getMinutes();
  var hseconds = nextDate.getSeconds();
  if (hmonth < 10) {
    hmonth = "0" + hmonth;
  }
  if (hdate < 10) {
    hdate = "0" + hdate;
  }
  if (hhours < 10) {
    hhours = "0" + hhours;
  }
  if (hminutes < 10) {
    hminutes = "0" + hminutes;
  }
  if (hseconds < 10) {
    hseconds = "0" + hseconds;
  }
  if (type == 1) {
    Mytime =
      year +
      "-" +
      month +
      "-" +
      date +
      " " +
      hours +
      ":" +
      minutes +
      ":" +
      seconds;
  } else if (type == 2) {
    Mytime = hyear + "-" + hmonth + "-" + hdate + " 12:00:00";
  }
  return Mytime;
}
//UTC时间格式转换  例：2019-09-06T06:16:45.044Z
function getUTCtime(type) {
  if (type.toString().indexOf("-") >= 0) {
    var d = new Date(Date.parse(type.replace(/-/g, "/")));
  } else {
    var d = new Date(type);
  }
  var nd = d.toISOString();

  return nd;
  //  console.log("Korean time is" + nd.toLocaleString());
}
function GetQueryString(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  var r = window.location.search.substr(1).match(reg);
  if (r != null) return decodeURI(r[2]);
  return null;
}
var myload;
var layer;
var table;
var laypage;
var form;
layui.use(["layer", "table", "form", "laypage"], function() {
  layer = layui.layer;
  form = layui.form;
  table = layui.table;
  laypage = layui.laypage;
});
function dourl(purl){
	var type=localStorage.getItem("type");
	if(type==1){
  	purl=purl.replace(/bapi/, "aapi")
  }
  else{
  	purl=purl.replace(/aapi/, "bapi")
  }
  return purl
}

function ajaxRequest(url, method, dtype, datas, callback, isshow) {
  if (datas.page) {
    datas.page = datas.page - 1;
  }
  var token = localStorage.getItem("token");
  if (!token) {
    token = "";
  }
  
  if (method == "GET" || method == "get") {
    var obj = datas;
    datas = 1;
    var str = "?";
    for (var key in obj) {
      if (str == "?") {
        str = str + key + "=" + obj[key];
      } else {
        str = str + "&" + key + "=" + obj[key];
      }
    }
    url = url + str;
  }
  if(isshow == 'wfw'){
    var purl = wgmurl + url
  }
  else{
    var purl = apiurl + url
  }
  var type=localStorage.getItem("type");
  
  $.ajax({
    type: method,
    url: encodeURI(purl),
    data: JSON.stringify(datas),
    dataType: dtype,
    async: true,
    cache: false,
    headers: {
      "Content-Type": "application/json;charset=utf-8",
      Authorization: token,
      "Access-Control-Allow-Origin": "*"
    },
    beforeSend: function(xhr, settings) {
      if (isshow == 1) {
      } else {
        myload = layer.load(1);
      }
    },
    success: function(ret) {
      //alert(JSON.stringify(ret))
      if (ret.success||ret.length>0) {
        callback(ret);
      } else {
        layer.msg(ret.message);
      }
    },
    complete: function() {
      layer.close(myload);
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
      if (XMLHttpRequest.responseText) {
        var str = XMLHttpRequest.responseText;
        var nstr = $.parseJSON(str);
      }
      if (
        nstr.message == "访问此资源需要身份验证" ||
        nstr.message == "token已过期或不正确"
      ) {
        layer.msg("登陆超时或未登陆，请重新登陆");
        setTimeout(function() {
          window.location.href = baseurl + "/#/login";
        }, 2000);
      } else {
        if (XMLHttpRequest.responseText) {
          var str = XMLHttpRequest.responseText;
          var nstr = $.parseJSON(str);
          if (nstr.message != "权限不足") {
            layer.msg(nstr.message);
          }
        }
      }
    }
  });
}
////判断浏览器大小调整弹窗大小
function screen() {
  var width = $(window).width();
  if (width > 1200) {
    return 3; //大屏幕
  } else if (width > 992) {
    return 2; //中屏幕
  } else if (width > 768) {
    return 1; //小屏幕
  } else {
    return 0; //超小屏幕
  }
}
